#include <bits/stdc++.h>
// 2025/02/03
// tag: 
// Author: Zhang Muen
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> a(n + 1);
    bitset<100001> vis;
    for (int i = 1; i <= n; i++)
        cin >> a[i].first, a[i].second = i;
    sort(a.begin() + 1, a.end());
    int cnt = 0, ans = 1;
    for (int i = 1; i <= n; i++){
        if (i < a[i].second)
            cnt++;
        if (vis[i] == true)
            cnt--;
        vis[a[i].second] = true;
        ans = max(ans, cnt);
    }
    cout << ans;
    return 0;
}